// pages/search-result-list/search-result-list.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    results:[
      {
        "id": 46,
        "t_date": "2020-01-26",
        "t_start": "2020-01-25T10:45:00.000Z",
        "t_end": "2020-01-25T16:20:00.000Z",
        "t_type": 1,
        "t_no": "TR134",
        "t_memo": "",
        "t_no_sub": "",
        "t_pos_start": "新加坡",
        "t_pos_end": "西安",
        "link": "https://mp.weixin.qq.com/s/jEBlMLCgSTD9AcpcV1yRtg",
        "source": "央视新闻",
        "verified": 1,
        "created_at": "2020-01-27T09:54:12.000Z",
        "updated_at": "2020-01-27T09:54:12.000Z"
      },
      {
          "id": 88,
          "t_date": "2020-01-25",
          "t_start": "2020-01-24T16:00:00.000Z",
          "t_end": "2020-01-25T15:59:59.000Z",
          "t_type": 2,
          "t_no": "8L9564",
          "t_memo": "",
          "t_no_sub": "",
          "t_pos_start": "杭州",
          "t_pos_end": "赣州",
          "link": "http://tt.m.jxnews.com.cn/news/91/911234.html?app=jxttn&from=groupmessage&isappinstalled=0",
          "source": "中国江西网-江南都市报",
          "verified": 1,
          "created_at": "2020-01-27T11:59:02.000Z",
          "updated_at": "2020-01-27T11:59:02.000Z"
      },
      {
          "id": 51,
          "t_date": "2020-01-24",
          "t_start": "2020-01-24T02:14:00.000Z",
          "t_end": "2020-01-24T13:06:00.000Z",
          "t_type": 3,
          "t_no": "D3286",
          "t_memo": "同车次乘客共有49人需采取防护措施",
          "t_no_sub": "",
          "t_pos_start": "汉口",
          "t_pos_end": "梅州西",
          "link": "https://mp.weixin.qq.com/s/jEBlMLCgSTD9AcpcV1yRtg",
          "source": "央视新闻",
          "verified": 1,
          "created_at": "2020-01-27T10:02:56.000Z",
          "updated_at": "2020-01-27T10:02:56.000Z"
      },
      {
          "id": 81,
          "t_date": "2020-01-24",
          "t_start": "2020-01-24T05:13:00.000Z",
          "t_end": "2020-01-24T15:59:59.000Z",
          "t_type": 4,
          "t_no": "西安市高陵区109路",
          "t_memo": "途径农机推广站、北环广场站到中医院",
          "t_no_sub": "",
          "t_pos_start": "西安市高陵区",
          "t_pos_end": "西安市高陵区",
          "link": "https://tech.sina.com.cn/roll/2020-01-27/doc-iihnzahk6529019.shtml",
          "source": "央视新闻",
          "verified": 1,
          "created_at": "2020-01-27T11:46:58.000Z",
          "updated_at": "2020-01-27T11:46:58.000Z"
      },
      {
          "id": 82,
          "t_date": "2020-01-24",
          "t_start": "2020-01-24T06:30:00.000Z",
          "t_end": "2020-01-24T15:59:59.000Z",
          "t_type": 5,
          "t_no": "西安市高陵区109路",
          "t_memo": "农机推广站、高交路口站、电力路口站、高陵汽车站、东方红路十字站、交警大队站、一中路口站、上林二路东口站",
          "t_no_sub": "",
          "t_pos_start": "北环广场站",
          "t_pos_end": "上林二路东口站",
          "link": "https://tech.sina.com.cn/roll/2020-01-27/doc-iihnzahk6529019.shtml",
          "source": "央视新闻",
          "verified": 1,
          "created_at": "2020-01-27T11:48:02.000Z",
          "updated_at": "2020-01-27T11:48:02.000Z"
      },
      {
          "id": 92,
          "t_date": "2020-01-24",
          "t_start": "2020-01-24T10:00:00.000Z",
          "t_end": "2020-01-24T15:59:59.000Z",
          "t_type": 6,
          "t_no": "包头32路公交车",
          "t_memo": "",
          "t_no_sub": "",
          "t_pos_start": "包头医学院第一附属医院",
          "t_pos_end": "包头市昆区团结大街九号街坊华龙苑住宅小区",
          "link": "https://weibo.com/2803301701/IroG4wQ2t?refer_flag=1001030103_&type=comment#_rnd1580126419505",
          "source": "人民日报",
          "verified": 1,
          "created_at": "2020-01-27T12:07:06.000Z",
          "updated_at": "2020-01-27T12:07:06.000Z"
      },
      {
          "id": 204,
          "t_date": "2020-01-24",
          "t_start": "2020-01-23T16:00:00.000Z",
          "t_end": "2020-01-24T15:59:59.000Z",
          "t_type": 7,
          "t_no": "G556",
          "t_memo": "",
          "t_no_sub": "2号车厢",
          "t_pos_start": "荆州",
          "t_pos_end": "郑州东",
          "link": "https://mp.weixin.qq.com/s?__biz=MjM5MzUwNjQwMQ==&mid=2651631249&idx=1&sn=62658db9cd4bcef160147d84ed333d96",
          "source": "郑州晚报",
          "verified": 1,
          "created_at": "2020-01-28T08:45:09.000Z",
          "updated_at": "2020-01-29T13:50:56.000Z"
      },
      {
          "id": 205,
          "t_date": "2020-01-24",
          "t_start": "2020-01-23T16:00:00.000Z",
          "t_end": "2020-01-24T15:59:59.000Z",
          "t_type": 8,
          "t_no": "G544",
          "t_memo": "",
          "t_no_sub": "2号车厢",
          "t_pos_start": "驻马店西",
          "t_pos_end": "郑州东",
          "link": "https://mp.weixin.qq.com/s?__biz=MjM5MzUwNjQwMQ==&mid=2651631249&idx=1&sn=62658db9cd4bcef160147d84ed333d96",
          "source": "郑州晚报",
          "verified": 1,
          "created_at": "2020-01-28T08:45:30.000Z",
          "updated_at": "2020-01-29T13:49:15.000Z"
      },
      {
          "id": 223,
          "t_date": "2020-01-24",
          "t_start": "2020-01-23T16:00:00.000Z",
          "t_end": "2020-01-24T15:59:59.000Z",
          "t_type": 0,
          "t_no": "热海景区、滇西抗战纪念馆",
          "t_memo": "",
          "t_no_sub": "",
          "t_pos_start": "热海",
          "t_pos_end": "",
          "link": "http://news.sina.com.cn/c/2020-01-28/doc-iihnzahk6685333.shtml",
          "source": "人民网",
          "verified": 1,
          "created_at": "2020-01-28T10:44:01.000Z",
          "updated_at": "2020-01-28T10:44:01.000Z"
      },
      {
          "id": 268,
          "t_date": "2020-01-23",
          "t_start": "2020-01-23T04:54:00.000Z",
          "t_end": "2020-01-23T06:37:00.000Z",
          "t_type": 2,
          "t_no": "D3936",
          "t_memo": "",
          "t_no_sub": "2车厢，9A",
          "t_pos_start": "昆明站",
          "t_pos_end": "祥云站",
          "link": "https://weibo.com/3802143838/IrAOGw6Ov",
          "source": "弥渡发布",
          "verified": 1,
          "created_at": "2020-01-29T11:22:39.000Z",
          "updated_at": "2020-01-29T11:22:39.000Z"
      },
      {
          "id": 269,
          "t_date": "2020-01-23",
          "t_start": "2020-01-22T23:10:00.000Z",
          "t_end": "2020-01-23T03:00:00.000Z",
          "t_type": 1,
          "t_no": "8L9894",
          "t_memo": "",
          "t_no_sub": "座次12A",
          "t_pos_start": "武汉",
          "t_pos_end": "昆明市长水机场",
          "link": "https://weibo.com/3802143838/IrAOGw6Ov",
          "source": "弥渡发布",
          "verified": 1,
          "created_at": "2020-01-29T11:24:20.000Z",
          "updated_at": "2020-01-29T11:24:20.000Z"
      },
      {
          "id": 270,
          "t_date": "2020-01-23",
          "t_start": "2020-01-23T03:30:00.000Z",
          "t_end": "2020-01-23T03:30:00.000Z",
          "t_type": 6,
          "t_no": "云A2B31W",
          "t_memo": "",
          "t_no_sub": "",
          "t_pos_start": "昆明市长水机场",
          "t_pos_end": "昆明站",
          "link": "https://weibo.com/3802143838/IrAOGw6Ov",
          "source": "弥渡发布",
          "verified": 1,
          "created_at": "2020-01-29T11:26:29.000Z",
          "updated_at": "2020-01-29T11:26:29.000Z"
      },
      {
          "id": 304,
          "t_date": "2020-01-23",
          "t_start": "2020-01-23T11:31:00.000Z",
          "t_end": "2020-01-24T08:45:00.000Z",
          "t_type": 2,
          "t_no": "Z265",
          "t_memo": "16间上铺",
          "t_no_sub": "13号车厢",
          "t_pos_start": "西宁",
          "t_pos_end": "拉萨",
          "link": "https://weitoutiao.zjurl.cn/ugc/share/thread/1657113362908167/?app=&target_app=13&wxshare_count=1&tt_from=weixin&utm_source=weixin&utm_medium=toutiao_android&utm_campaign=client_share",
          "source": "央视新闻",
          "verified": 1,
          "created_at": "2020-01-30T02:45:09.000Z",
          "updated_at": "2020-01-30T02:45:33.000Z"
      },
      {
          "id": 50,
          "t_date": "2020-01-23",
          "t_start": "2020-01-23T01:57:00.000Z",
          "t_end": "2020-01-23T15:59:59.000Z",
          "t_type": 4,
          "t_no": "南充川R60720",
          "t_memo": "",
          "t_no_sub": "",
          "t_pos_start": "南充",
          "t_pos_end": "武胜县烈面镇",
          "link": "https://mp.weixin.qq.com/s/jEBlMLCgSTD9AcpcV1yRtg",
          "source": "央视新闻",
          "verified": 1,
          "created_at": "2020-01-27T10:02:43.000Z",
          "updated_at": "2020-01-27T10:02:43.000Z"
      },
      {
          "id": 52,
          "t_date": "2020-01-23",
          "t_start": "2020-01-23T00:14:00.000Z",
          "t_end": "2020-01-23T00:28:00.000Z",
          "t_type": 5,
          "t_no": "锡林浩特市3路公交车",
          "t_memo": "",
          "t_no_sub": "",
          "t_pos_start": "报社站",
          "t_pos_end": "盟医院站",
          "link": "https://mp.weixin.qq.com/s/jEBlMLCgSTD9AcpcV1yRtg",
          "source": "央视新闻",
          "verified": 1,
          "created_at": "2020-01-27T10:04:52.000Z",
          "updated_at": "2020-01-27T10:04:52.000Z"
      },
      {
          "id": 53,
          "t_date": "2020-01-23",
          "t_start": "2020-01-22T23:55:00.000Z",
          "t_end": "2020-01-23T12:28:00.000Z",
          "t_type": 2,
          "t_no": "G1278",
          "t_memo": "同车厢共有乘客53人",
          "t_no_sub": "2号车厢",
          "t_pos_start": "武汉汉口",
          "t_pos_end": "哈尔滨西",
          "link": "https://mp.weixin.qq.com/s/jEBlMLCgSTD9AcpcV1yRtg",
          "source": "央视新闻",
          "verified": 1,
          "created_at": "2020-01-27T10:06:36.000Z",
          "updated_at": "2020-01-29T16:24:27.000Z"
      },
      {
          "id": 61,
          "t_date": "2020-01-23",
          "t_start": "2020-01-23T02:00:00.000Z",
          "t_end": "2020-01-23T15:59:59.000Z",
          "t_type": 5,
          "t_no": "本溪28路公交车",
          "t_memo": "",
          "t_no_sub": "",
          "t_pos_start": "顺山车站",
          "t_pos_end": "本钢总院",
          "link": "https://baijiahao.baidu.com/s?id=1656758480273984649&wfr=spider&for=pc",
          "source": "中国日报网",
          "verified": 1,
          "created_at": "2020-01-27T10:56:54.000Z",
          "updated_at": "2020-01-27T10:56:54.000Z"
      },
      {
          "id": 121,
          "t_date": "2020-01-23",
          "t_start": "2020-01-23T04:10:00.000Z",
          "t_end": "2020-01-23T15:59:59.000Z",
          "t_type": 5,
          "t_no": "富平县陕ED0098号",
          "t_memo": "",
          "t_no_sub": "",
          "t_pos_start": "富平县新华大厦门前",
          "t_pos_end": "到贤镇",
          "link": "http://news.hsw.cn/system/2020/0127/1149962.shtml",
          "source": "富平县疾病预防控制中心",
          "verified": 1,
          "created_at": "2020-01-27T13:02:14.000Z",
          "updated_at": "2020-01-27T13:02:14.000Z"
      },
      {
          "id": 131,
          "t_date": "2020-01-23",
          "t_start": "2020-01-23T00:30:00.000Z",
          "t_end": "2020-01-23T15:59:59.000Z",
          "t_type": 4,
          "t_no": "重庆市潼南县渝A6G126",
          "t_memo": "",
          "t_no_sub": "",
          "t_pos_start": "重庆市潼南县宝龙镇斩草村",
          "t_pos_end": "重庆市潼南县宝龙镇",
          "link": "http://news.sina.com.cn/c/2020-01-27/doc-iihnzahk6537657.shtml",
          "source": "人民日报",
          "verified": 1,
          "created_at": "2020-01-27T13:13:47.000Z",
          "updated_at": "2020-01-27T13:13:47.000Z"
      },
      {
          "id": 133,
          "t_date": "2020-01-23",
          "t_start": "2020-01-23T00:50:00.000Z",
          "t_end": "2020-01-23T15:59:59.000Z",
          "t_type": 4,
          "t_no": "重庆市潼南县渝A3G389",
          "t_memo": "",
          "t_no_sub": "",
          "t_pos_start": "重庆市潼南县宝龙镇斩草村",
          "t_pos_end": "重庆市潼南县古溪车站",
          "link": "http://news.sina.com.cn/c/2020-01-27/doc-iihnzahk6537657.shtml",
          "source": "人民日报",
          "verified": 1,
          "created_at": "2020-01-27T13:14:35.000Z",
          "updated_at": "2020-01-27T13:14:35.000Z"
      },
      {
          "id": 134,
          "t_date": "2020-01-23",
          "t_start": "2020-01-23T00:54:00.000Z",
          "t_end": "2020-01-23T15:59:59.000Z",
          "t_type": 5,
          "t_no": "重庆市潼南县渝C85905",
          "t_memo": "",
          "t_no_sub": "",
          "t_pos_start": "重庆市潼南县古溪车站",
          "t_pos_end": "重庆市潼南县上城华府站",
          "link": "http://news.sina.com.cn/c/2020-01-27/doc-iihnzahk6537657.shtml",
          "source": "人民日报",
          "verified": 1,
          "created_at": "2020-01-27T13:15:16.000Z",
          "updated_at": "2020-01-27T13:15:16.000Z"
      },
      {
          "id": 201,
          "t_date": "2020-01-23",
          "t_start": "2020-01-22T16:00:00.000Z",
          "t_end": "2020-01-23T15:59:59.000Z",
          "t_type": 2,
          "t_no": "G1807",
          "t_memo": "",
          "t_no_sub": "12号车厢",
          "t_pos_start": "永城北",
          "t_pos_end": "郑州东",
          "link": "https://mp.weixin.qq.com/s?__biz=MjM5MzUwNjQwMQ==&mid=2651631249&idx=1&sn=62658db9cd4bcef160147d84ed333d96",
          "source": "郑州晚报",
          "verified": 1,
          "created_at": "2020-01-28T08:44:33.000Z",
          "updated_at": "2020-01-29T13:50:56.000Z"
      },
      {
          "id": 202,
          "t_date": "2020-01-23",
          "t_start": "2020-01-22T16:00:00.000Z",
          "t_end": "2020-01-23T15:59:59.000Z",
          "t_type": 2,
          "t_no": "G422",
          "t_memo": "",
          "t_no_sub": "5号车厢",
          "t_pos_start": "信阳东",
          "t_pos_end": "郑州东",
          "link": "https://mp.weixin.qq.com/s?__biz=MjM5MzUwNjQwMQ==&mid=2651631249&idx=1&sn=62658db9cd4bcef160147d84ed333d96",
          "source": "郑州晚报",
          "verified": 1,
          "created_at": "2020-01-28T08:44:48.000Z",
          "updated_at": "2020-01-29T13:50:56.000Z"
      }
    ],
    // 行程信息
    journeys:[],
    // 是否还有更多
    hasMore:true,
    // 是否显示底部提示文字
    showBottomHintText:true,
    // 底部提示文字
    bottomHintText:'加载中...'
  },

  value:{
    limit:20, // 限制条数
    offset:0 // 跳过条数
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(options.data)
    // console.log(options.region)
    // console.log(options.type)
    // console.log(options.site)

    if(options.title!=null && options.title!=""){
        wx.setNavigationBarTitle({
          title: options.title,
        })
    }
 
 
    // search赋值
    this.value.search = options
    // 执行搜索
    this.getAndShowJourneys()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.value.offset=0
    this.value.limit=20

    this.setData({
        hasMore:true,
        bottomHintText:"加载中...",
        journeys:[],
        showBottomHintText:true
    })
    this.getAndShowJourneys()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.hasMore){
        wx.showNavigationBarLoading({
            complete: (res) => {},
        })
        this.setData({
            showBottomHintText:true
        })
        this.getAndShowJourneys()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return{
        title:"确诊患者相同行程查询结果"
    }
  },

  toSearchResultDetail: function (e) {
    wx.navigateTo({
      url: '/pages/search-result-detail/search-result-detail?id=' + e.currentTarget.dataset.id,
    })
  },

  
  // 获取并显示行程
  getAndShowJourneys: function(){
    var that = this;
    wx.request({
      url: app.journeySearchApi,
      data:{
          date: that.value.search.date,
          region: that.value.search.region,
          type: that.value.search.type,
          site: that.value.search.site,
          offset: that.value.offset,
          limit: that.value.limit
      },
      success(res){
          if(res.data.code == 0){
            if(res.data.result.journeys.length>0){
                // 追加
                that.setData({
                    journeys: that.data.journeys.concat(res.data.result.journeys),
                    showBottomHintText:false
                })
                that.value.offset += res.data.result.journeys.length
            }
            if(res.data.result.journeys.length < that.value.limit){
                // 没有更多了
                that.setData({
                    hasMore: false,
                    bottomHintText: "查询到" + that.data.journeys.length + "条行程信息",
                    showBottomHintText:true
                })
            }
          }
          wx.hideNavigationBarLoading({
            complete: (res) => {},
          })
          wx.stopPullDownRefresh({
            complete: (res) => {},
          })
      }
    })
  },

  // 联系我
  toContact:function(res) {
      wx.navigateTo({
        url: '/pages/more/contact/contact',
      })
  }
})